﻿using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;

public class ImageItem : MonoBehaviour,IDragHandler,IBeginDragHandler,IEndDragHandler,IPointerClickHandler
{


    public RectTransform MyTran;
    private Tween ScaleTween;
    public bool IsBig;

    private void Awake()
    {
        MyTran = GetComponent<RectTransform>();
        ScaleTween = MyTran.DOScale(2, 0.2f);
        ScaleTween.SetAutoKill(false);
        ScaleTween.SetEase(Ease.Linear);
        ScaleTween.Pause();
    }

    public void OnDrag(PointerEventData eventData)
    {
        print(MyTran.anchoredPosition +",鼠标位置:"+ eventData.position);
        MyTran.DOAnchorPos(eventData.position, 0.6f);
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        print("拖拽开始");
        
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        print("结束拖拽");
    }

    /// <summary>
    /// 点击事件
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerClick(PointerEventData eventData)
    {
        if (!IsBig)
        {
            //放大
            print("放大");
            ScaleTween.PlayForward();
            IsBig = true;
        }
        else
        {
            //缩小
            print("缩小");
            ScaleTween.PlayBackwards();
            IsBig = false;
        }
    }
}
